package com.teamclub.util.network;

import com.teamclub.util.libs.F;
import com.teamclub.util.libs.Json;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;

/**
 * Created by zhangmeng on 17-2-10.
 */
public class HttpRespEntity {
    private Logger logger = LoggerFactory.getLogger(HttpRespEntity.class);
    private byte[] content;

    public HttpRespEntity(byte[] content) {
        this.content = content;
    }


    public F.Option<String> toStr(){
        try {
            return F.Option.Some(new String(content, "UTF-8"));
        } catch(Exception e) {
            logger.error("" ,e);
            return F.Option.None();
        }

    }

    public <T> F.Option<T> toGene(Class<T> clazz) {
        try {
            String str = new String(content, "UTF-8");
            T t = Json.fromJson(Json.parse(str), clazz);
            return F.Option.Some(t);
        }catch (Exception e) {
            logger.error("", e);
            return F.Option.None();
        }
    }

    public byte[] getRaw(){
        return content;
    }
}
